 package com.jcrj.action.flow;
 
 import com.jcrj.action.BaseAction;
 import com.jcrj.entity.OHoliday;
 import com.jcrj.entity.OLeave;
 import com.jcrj.entity.OUser;
 import com.jcrj.service.HolidayService;
 import com.jcrj.util.DateUtil;
 import java.io.PrintWriter;
 import java.util.List;
 import java.util.Map;
 import javax.servlet.http.HttpServletResponse;
 import net.sf.json.JSONObject;
 
 public class HolidayAction extends BaseAction
 {
   private String name;
   private String account;
   private String year;
   private String orgName;
   private List<OHoliday> holidayList;
   private List<OLeave> leaveList;
   private HolidayService holidayService;
   private Long totalCount;
   private Long pageCount;
   private String userId;
 
   public String getHolidayTotalList()
   {
     try
     {
       this.holidayList = this.holidayService.getHolidayTotalList(this.name, this.account, getYear(), this.orgName, getCurrentPage());
       this.totalCount = this.holidayService.countHolidayTotal(this.name, this.account, getYear(), this.orgName);
       this.pageCount = Long.valueOf((this.totalCount.longValue() - 1L) / 10L + 1L);
     } catch (Exception e) {
       e.printStackTrace();
     }
     return "success";
   }
 
   public String getLeaveTotalList() {
     try {
       this.leaveList = this.holidayService.getLeaveTotalList(this.name, this.account, getYear(), this.orgName, getCurrentPage());
       this.totalCount = this.holidayService.countLeaveTotal(this.name, this.account, getYear(), this.orgName);
       this.pageCount = Long.valueOf((this.totalCount.longValue() - 1L) / 10L + 1L);
     } catch (Exception e) {
       e.printStackTrace();
     }
     return "success";
   }
 
   public String getMyHolidayTotal() {
     try {
       long total = 0L;
       long preTotal = 0L;
       long preHoliday = 0L;
       OUser user = null;
       int year = Integer.parseInt(DateUtil.getYear());
       if ((this.userId == null) || ("".equals(this.userId)))
         user = (OUser)getSession().get("userInfo");
       else {
         user = this.holidayService.getUserObj(Integer.parseInt(this.userId));
       }
       JSONObject json = new JSONObject();
       if ((user.getWorkDate() != null) && (!"".equals(user.getWorkDate()))) {
         int work = Integer.parseInt(user.getWorkDate());
         long nowHolidays = getHolidaysTotal(year, work, user.getId().intValue());
         long preHolidays = getHolidaysTotal(year - 1, work, user.getId().intValue());
         if (nowHolidays > 0L) {
           total = this.holidayService.myHolidayTotal(user.getId().intValue(), year).longValue();
         }
         if (preHolidays > 0L) {
           preTotal = this.holidayService.myHolidayTotal(user.getId().intValue(), year - 1).longValue();
         }
         if (preHolidays - preTotal < 0L)
           preHoliday = 0L;
         else {
           preHoliday = preHolidays - preTotal;
         }
         json.put("preHoliday", Long.valueOf(preHoliday));
         json.put("nowHoliday", Long.valueOf(nowHolidays));
         json.put("total", Long.valueOf(total));
         getResponse().getWriter().write(json.toString());
       } else {
         json.put("preHoliday", Integer.valueOf(0));
         json.put("nowHoliday", Integer.valueOf(0));
         json.put("total", Integer.valueOf(0));
         getResponse().getWriter().write(json.toString());
       }
     }
     catch (Exception e)
     {
       e.printStackTrace();
     }
     return null;
   }
 
   private long getHolidaysTotal(int year, int work, int userId) {
     OLeave leaves = this.holidayService.myLeaveTotals(userId, year);
     long holidays = 0L;
     if ((Integer.parseInt(leaves.getDays1()) < 20) && (Integer.parseInt(leaves.getDays2()) < 60)) {
       if ((year - work >= 1) && (year - work < 10))
         holidays = 5L;
       else if ((year - work >= 10) && (year - work < 20))
         holidays = 10L;
       else if (year - work >= 20) {
         holidays = 15L;
       }
     }
     return holidays;
   }
 
   public String getMyLeaveTotal() {
     try {
       long total = 0L;
 
       int year = Integer.parseInt(DateUtil.getYear());
       OLeave leaves;
       if ((this.userId == null) || ("".equals(this.userId))) {
         OUser user = (OUser)getSession().get("userInfo");
         leaves = this.holidayService.myLeaveTotals(user.getId().intValue(), year);
       } else {
         leaves = this.holidayService.myLeaveTotals(Integer.parseInt(this.userId), year);
       }
       JSONObject json = new JSONObject();
       json.put("leave", leaves);
       getResponse().getWriter().write(json.toString());
     } catch (Exception e) {
       e.printStackTrace();
     }
     return null;
   }
   public String getName() {
     return this.name;
   }
   public void setName(String name) {
     this.name = name;
   }
   public String getAccount() {
     return this.account;
   }
   public void setAccount(String account) {
     this.account = account;
   }
 
   public List<OHoliday> getHolidayList() {
     return this.holidayList;
   }
 
   public void setHolidayList(List<OHoliday> holidayList) {
     this.holidayList = holidayList;
   }
 
   public HolidayService getHolidayService() {
     return this.holidayService;
   }
   public void setHolidayService(HolidayService holidayService) {
     this.holidayService = holidayService;
   }
 
   public Long getTotalCount() {
     return this.totalCount;
   }
 
   public void setTotalCount(Long totalCount) {
     this.totalCount = totalCount;
   }
 
   public Long getPageCount() {
     return this.pageCount;
   }
 
   public void setPageCount(Long pageCount) {
     this.pageCount = pageCount;
   }
 
   public String getUserId() {
     return this.userId;
   }
 
   public void setUserId(String userId) {
     this.userId = userId;
   }
 
   public List<OLeave> getLeaveList() {
     return this.leaveList;
   }
 
   public void setLeaveList(List<OLeave> leaveList) {
     this.leaveList = leaveList;
   }
 
   public String getYear() {
     return (this.year == null) || ("".equals(this.year)) ? DateUtil.getYear() : this.year;
   }
 
   public void setYear(String year) {
     this.year = year;
   }
 
   public String getOrgName() {
     return this.orgName;
   }
 
   public void setOrgName(String orgName) {
     this.orgName = orgName;
   }
 }